//
//  RefuseOrderListProxy.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/17.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "RefuseOrderListProxy.h"
#import "JFBRefuseOrderDS.h"
#import "RefuseOrderCell.h"
#import "JFBLoadingAnimation.h"

@implementation RefuseOrderListProxy


- (void)reload:(__unused id)sender {
    JFBLoadingAnimation * animation = [[JFBLoadingAnimation alloc] init:self.tableView];
    [JFBRefuseOrderDS loadOrderList:^(NSArray *orders, NSError *error) {
        [animation stop];
        self.items = [@[] mutableCopy];
        if (error || orders.count == 0) {
            [ComponentsUtils emptyStringTips:self.tableView tips:@"当前没有订单，继续努力哦～"];
        } else {
            if( self.items.count == 0 ) {
                [ComponentsUtils cleanEmptyTips:self.tableView];
            }
            _cellFrame = [[NSMutableDictionary alloc] init];
            
            [self.items addObjectsFromArray:orders];
        }
        [self.tableView reloadData];
    } pager:self.pager];
}

-(void)loadNewData {
    [JFBRefuseOrderDS loadOrderList:^(NSArray *orders, NSError *error) {
        [self.tableView.header endRefreshing];
         self.items = [@[] mutableCopy];
        if (error || orders.count == 0) {
            [ComponentsUtils emptyStringTips:self.tableView tips:@"当前没有订单，继续努力哦～"];
        } else {
            if( self.items.count == 0 ) {
                [ComponentsUtils cleanEmptyTips:self.tableView];
            }
            _cellFrame = [[NSMutableDictionary alloc] init];
           
            [self.items addObjectsFromArray:orders];
        }
        [self.tableView reloadData];
    } pager:self.pager];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    NSObject *obj = self.items[indexPath.row];
    static NSString *cellIdentifier = @"OrderCompleteCellIdentifier";
    cell= [[RefuseOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier frame:self.tableView.bounds];
    ((RefuseOrderCell*)cell).order = (JFBRefuseOrderDS*)obj;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
@end
